//index.js
const app = getApp()
import activeApi from '../../api/activeApi'
import share from '../../behaviors/share'
Page({
  behaviors: [share],
  data: {
    avatarUrl: '',
    userInfo: {},

    isShowAdd: false
  },

  onLoad: function() {
  
    let userInfo = wx.getStorageSync('userInfo')
    if (userInfo) {
     
      app.globalData.userInfo = userInfo
    }
  },


  headClick: function(e) {
    wx.navigateTo({
      url: '/pages/login/login'
    })
  },

  toAdd(){
    wx.navigateTo({
      url: '/pages/addActive/addActive?action=add'
    })
    
    // if(app.globalData.userInfo){
    //   wx.navigateTo({
    //     url: '/pages/addActive/addActive?action=add'
    //   })
    // }else{
    //   wx.navigateTo({
    //     url: '/pages/login/login'
    //   })
    // }
  },
  toMyActive(){
    wx.navigateTo({
      url: '/pages/activeList/activeList?type=myActive'
    })
    // if (app.globalData.userInfo) {
    //   wx.navigateTo({
    //     url: '/pages/activeList/activeList?type=myActive'
    //   })
    // } else {
    //   wx.navigateTo({
    //     url: '/pages/login/login'
    //   })
    // }
  },
  toMyJoin(){
    if (app.globalData.userInfo) {
      wx.navigateTo({
        url: '/pages/activeList/activeList?type=myJoinActive'
      })
    } else {
      wx.navigateTo({
        url: '/pages/login/login'
      })
    }
  },
  toBaijia(){
    wx.navigateToMiniProgram({
      appId: 'wx5da44835dac1892e'
    })
  },
  onShow(){
    if( app.globalData.userInfo){
      this.setData({
        avatarUrl: app.globalData.userInfo.avatarUrl,
        userInfo: app.globalData.userInfo
      })
    }
  },

  onShareAppMessage: function () {
    return {
      title: '这是一个记事本备忘录',
      imageUrl: 'https://public-server-center-prod-1258963190.cos.ap-guangzhou.myqcloud.com/studentCard/20210521153238.jpg'
    }
  }

})
